﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

using Pamela.Logic.Helpers;
using Pamela.Logic.ProjectFiles.Base;

namespace Pamela.Logic.ProjectFiles.Base
{
    public abstract class ProjectFileBase : IDisposable
    {
        protected string path;
        protected string selectedModel;
        protected List<string> lines;
        protected bool rollback;

        protected bool HasBeenValidated = false;

        protected ProjectFileBase(BuilderInfo builderInfo)
        {
            this.selectedModel = builderInfo.SelectedModel;            
            this.rollback = false;
        }

        public void Dispose()
        {
            if (!this.rollback)
            {
                File.WriteAllLines(path, lines);
            }
        }

        public void Rollback()
        {
            this.rollback = true;
        }

        public abstract bool Validate();
        public abstract void Update();        
    }
}
